package cn.zhoutao.auth.listener;

import cn.zhoutao.auth.service.IPermissionScanService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import javax.servlet.annotation.WebListener;

@WebListener//申明自定义的web监听器，被容器注册和使用
@Slf4j
public class PermissionScanListener implements ServletContextListener {

    @Autowired
    private IPermissionScanService permissionScanService;

    /**
     * spring容器装载完成执行此方法
     * @param servletContextEvent
     */
    @Override
    public void contextInitialized(ServletContextEvent servletContextEvent) {
        new Thread(new Runnable() {
            //执行异步线程业务
            @Override
            public void run() {
                log.info("开启权限扫描");

                permissionScanService.scan();
                log.info("结束权限扫描");
            }
        }).start();//启动异步线程
    }
}